package com.roadmap.client.module;

import java.util.Date;
import java.util.List;

import com.roadmap.client.common.SimpleResult;
import com.roadmap.client.module.user.ActRecorder;
import com.roadmap.common.BaseEntity;
import com.roadmap.entities.Aspirant;
import com.roadmap.exception.ActionNotSupportedException;
import com.roadmap.exception.EntityNotFoundException;
import com.roadmap.exception.InvalidActionException;
import com.roadmap.exception.InvalidQueryException;
import com.roadmap.exception.InvalidStatusException;
import com.roadmap.exception.InvalidValueException;
import com.roadmap.exception.NullObjectException;
import com.roadmap.exception.ServerException;
import com.roadmap.repo.db.IDatabaseUtility;

/** Manager is to manage entities such goals, plans, tasks and so on. */
public interface IManager {
	/**
	 * create an entity record in database
	 */
	public void create(BaseEntity entity) throws NullObjectException,
			InvalidActionException, InvalidValueException, ServerException,
			EntityNotFoundException, ActionNotSupportedException,
			InvalidStatusException;

	/** get an entity record by its id from database */
	public BaseEntity get(String entityId) throws NullObjectException,
			InvalidQueryException, ServerException, InvalidValueException;
	
	/** get an extended entity record by its id from database */
	public BaseEntity getEntityExt(String entityId) throws NullObjectException,
			InvalidQueryException, ServerException, InvalidValueException;

	/** update the entity record in database */
	public void edit(BaseEntity entity) throws NullObjectException,
			InvalidActionException, InvalidValueException, ServerException;

	/** delete the entity record from database */
	public void delete(BaseEntity entity) throws NullObjectException,
			InvalidActionException, InvalidValueException, ServerException,
			EntityNotFoundException, ActionNotSupportedException;

	/** complete the entity if it has a status COMPLETED 
	 * @throws InvalidStatusException */
	public void complete(BaseEntity entity) throws NullObjectException,
			InvalidActionException, InvalidValueException, ServerException,
			EntityNotFoundException, ActionNotSupportedException, InvalidStatusException;

	/** complete the entity if it has a status CANCLED */
	public void cancel(BaseEntity entity) throws NullObjectException,
			InvalidActionException, InvalidValueException, ServerException,
			EntityNotFoundException, ActionNotSupportedException;

	/**
	 * restore the entity from CANCLED to other statuses if it has a status
	 * CANCLED
	 * 
	 * @throws InvalidValueException
	 * @throws EntityNotFoundException
	 * @throws ServerException
	 * @throws InvalidActionException
	 */
	public void restore(BaseEntity entity, int targetStatus)
			throws ActionNotSupportedException, InvalidValueException,
			InvalidActionException, ServerException, EntityNotFoundException;

	/** copy a instance of the entity */
	public void copy(BaseEntity entity) throws ActionNotSupportedException;

	/**
	 * get a list of entities if the entity supports status
	 * 
	 * @throws InvalidValueException
	 * @throws ServerException
	 * @throws InvalidQueryException
	 */
	public List getEntitiesByStatus(int[] states)
			throws ActionNotSupportedException, InvalidValueException,
			InvalidQueryException, ServerException;

	/**
	 * get a list of entities whose a time field is between a date scope
	 * 
	 */
	public List getEntitiesInDateScope(Date first, Date last)
			throws ActionNotSupportedException, NullObjectException,
			InvalidActionException, InvalidValueException, ServerException;

	/** get a list of entities which belong to the manager's parent */
	public List getEntitiesOfParent() throws NullObjectException,
			InvalidQueryException, ServerException, InvalidValueException;

	/** get a list of entities which belong to the manager's owner person */
	public List getEntitiesOfAspirant() throws NullObjectException,
			InvalidQueryException, ServerException, InvalidValueException;

	/** get the id of the manager's owner person */
	public String getOwnerId();

	/** who control the manager */
	public Aspirant getOwner() throws NullObjectException,
			InvalidQueryException, ServerException, InvalidValueException;

	/**
	 * The parent has the objects to be managed. E.g. the manager is to manage
	 * goals whose parent is a Aspirant. If the manager is to manage plans whose
	 * parent should be a goal.
	 */
	public BaseEntity getParent();

	/** set the boss of the manager */
	public void setParent(BaseEntity parent);

	/** get a database connection */
	public IDatabaseUtility getDbUtil();

	/* get the activity recorder of the manager 
	// public ActRecorder getActRecorder();
	 * 
	 */

	/** get the type of the entity to be managed */
	public Class getManagedEntityType();

	/**
	 * only support those entities who have status, including goal, plan and
	 * task. plan's status == its goal's status
	 * 
	 * @throws ActionNotSupportedException
	 * @throws ServerException
	 * @throws InvalidValueException
	 * @throws InvalidQueryException
	 */
	public List getExecutableEntities() throws ActionNotSupportedException,
			InvalidQueryException, InvalidValueException, ServerException;

	/**
	 * only support those entities who have status, including goal, plan and
	 * task. plan's status == its goal's status
	 * 
	 * @throws ActionNotSupportedException
	 * @return : A description of the entity's health symptom
	 * @throws InvalidValueException
	 */
	public String getEntityHealthy(BaseEntity entity) throws ActionNotSupportedException, InvalidValueException;

}
